﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Furion.CMS.Domain
{
    /// <summary>
    /// 任务执行记录
    /// </summary>
    public class CrontabExecuteRecord : Entity, IEntityTypeBuilder<CrontabExecuteRecord>
    {
        public CrontabExecuteRecord()
        {
            CreatedTime = DateTimeOffset.UtcNow;
        }

        /// <summary>
        /// 任务id
        /// </summary>
        public Guid TaskId { get; set; }
        /// <summary>
        /// 任务
        /// </summary>
        public virtual CrontabInfo Task { get; set; }
        /// <summary>
        /// 执行结果
        /// </summary>
        [MaxLength(400)]
        public string Result { get; set; }
        /// <summary>
        /// 执行状态
        /// </summary>
        public CrontabExecuteStatus ExecuteStatus { get; set; }

        public void Configure(EntityTypeBuilder<CrontabExecuteRecord> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.UseDefaultTableNameDefine();

            entityBuilder.HasIndex(i => i.TaskId);
        }
    }
}
